print("------------ map ------------")
let numbers1 = [1, 3, 5, 8, 7]
let numbers2 = numbers1.map{ $0 * 2}
print(numbers2)

print("------------ filter ------------")
let numbers3 = numbers1.filter{ $0 > 4 }
print(numbers3)

print("------------ reduce ------------")
let numbers4 = numbers1.reduce(0) { $0 + $1 }
print(numbers4)

print("------------ flatMap ------------")
let numbers5 = [[1, 3, 5, 8, 7], [12, 33], [10, 8]]
let numbers6 = numbers5.flatMap{
    $0.map {
        $0 * 2
    }
}
print(numbers6)

print("------------ compactMap(过滤空值) ------------")
let names = ["zhangsan", nil, "lisi", "wangwu", nil, "zhaoliu"]
let names1 = names.compactMap{ $0 }
print(names1)
